
 
 
 
 
 
 

set scheme s1color

/*** START CODE ***/


// Preamble
// ----------------------------
capture log close
clear all
*version 14.2
set more off
set matsize 800

 



// Data Preparation
*do "${Code}/Prepare_SpatialRD_data.do"

/*Scatter plots of electricity / gas prices*/

use "${Data_Clean}/spatial_RD_regdata.dta", clear

gen abs_delta_p_e_active = abs(delta_p_e_active)

graph twoway (scatter delta_p_e_active delta_obswgtprice_lt3_, msize(tiny)) (lfit delta_p_e_active delta_obswgtprice_lt3_ , lp(dash) lc(red*.8)), ///
ytitle("Electricity Price Differential (c/kwh)")  xtitle("Gas Price Differential (c\gal)") legend(off) ///
note("Gas prices based on 3 mile radius around zip centroid.")
graph export "${ResultsOut}/Figures/delta_gas_3mi_elec_scatter.pdf", replace

graph twoway (scatter delta_p_e_active delta_obswgtprice_lt3_, msize(tiny)) (lfit delta_p_e_active delta_obswgtprice_lt3_, lp(dash) lc(red*.8))  if distance_btw_cbg0 < 5000, ///
ytitle("Electricity Price Differential (c/kwh)")  xtitle("Gas Price Differential (c\gal)") legend(off) ///
note("Gas prices based on 3 mile radius around zip centroid.")
graph export "${ResultsOut}/Figures/delta_gas_3mi_elec_scatter_5km.pdf", replace

graph twoway scatter delta_P_gas distance_btw_cbg0 

graph twoway histogram delta_p_e_active, xtitle("Electricity Price Differential (c/kwh)")
graph export "${ResultsOut}/Figures/delta_p_e_histogram.pdf", replace 

graph twoway histogram delta_P_gas, xtitle("Gas Price Differential (c\gal)")
graph export "${ResultsOut}/Figures/delta_gas_price_histogram.pdf", replace 

graph twoway kdensity delta_P_gas || kdensity delta_obswgtprice_lt3, ///
legend(order(1 "Avg Price in Zip" 2 "Avg Price within 3 miles")) ///
xtitle("Cents per gallon") title("Kdensity of Difference in Gas Prices in Border Zips")

graph export "${ResultsOut}/Figures/kdensity_gas_prices.pdf", replace


*Residual gasoline price scatter plot for referee (JPE Micro round 2, January 2025)

preserve
local delta_demog "delta_population delta_pop_density delta_income"
local delta_dist "cons i.groupid#c.IOU_dist i.groupid#c.muni_dist"
local other_cov "delta_fuel_economy_mean delta_hybrid_share delta_luxury_share delta_mud_hh_share"


reg delta_obswgtprice_lt3 `delta_demog' `delta_dist' `other_cov'
predict resid_gas2, resid

*reg delta_P_gas cons i.groupid#c.IOU_dist i.groupid#c.muni_dist delta_pop_density delta_mud_hh_share
*predict resid_gas2, resid

graph twoway (scatter delta_p_e_active resid_gas2, msize(tiny)) (lfit delta_p_e_active resid_gas2, lp(dash) lc(red*.8)), ///
ytitle("Electricity Price Differential (c/kwh)")  xtitle("Gas Price Residual (c\gal)") legend(off)
graph export "${ResultsOut}/Figures/delta_gasresid_elec_scatter.pdf", replace


gen combined_dist = IOU_dist+muni_dist
graph twoway (scatter combined_dist resid_gas2, msize(tiny)) (lfit combined_dist resid_gas2, lp(dash) lc(red*.8)), ///
ytitle("IOU + Muni Distance")  xtitle("Gas Price Residual (c\gal)") legend(off)
graph export "${ResultsOut}/Figures/delta_gasresid_runvar_scatter.pdf", replace

graph twoway (scatter IOU_dist resid_gas2, msize(tiny)) (lfit IOU_dist resid_gas2, lp(dash) lc(red*.8)), ///
ytitle("IOU Distance")  xtitle("Gas Price Residual (c\gal)") legend(off)
graph export "${ResultsOut}/Figures/delta_gasresid_IOUdist_scatter.pdf", replace

graph twoway (scatter muni_dist resid_gas2, msize(tiny)) (lfit muni_dist resid_gas2, lp(dash) lc(red*.8)), ///
ytitle("Muni Distance")  xtitle("Gas Price Residual (c\gal)") legend(off)
graph export "${ResultsOut}/Figures/delta_gasresid_MUNIdist_scatter.pdf", replace


*Plot of gasoline prices against hybrid vehicle share

binscatter delta_fuel_economy_mean delta_obswgtprice_lt3, n(15) ///
ytitle("Average Fuel Economy Differential, 2013")  xtitle("Gas Price Differential (c\gal)") legend(off)

reg delta_fuel_economy_mean delta_obswgtprice_lt3, robust

sum *share0 *economy_mean0 obswgtprice_lt3_0 

restore

/*Reduced Form Plots conditioning on covariates*/


local delta_demog "delta_population delta_pop_density delta_income"
local delta_dist "cons i.groupid#c.IOU_dist i.groupid#c.muni_dist"
local other_cov "delta_fuel_economy_mean delta_hybrid_share delta_luxury_share delta_mud_hh_share"
local numpoints = 30

gen delta_p_e_permile = delta_p_e_active/4
gen delta_P_gas_permile = delta_P_gas/35


    rename delta_invdistwgtprice_lt3_ delta_idwP_gas_lt3
	gen delta_idwP_gas_lt3_pm = delta_idwP_gas_lt3/35
    rename delta_obswgtprice_lt3_ delta_owP_gas_lt3
	gen delta_owP_gas_lt3_pm = delta_owP_gas_lt3/35


foreach x in delta_share_BEV delta_P_gas delta_p_e_active delta_owP_gas_lt3 delta_p_e_permile delta_P_gas_permile delta_owP_gas_lt3_pm {
reghdfe `x' `delta_demog' `other_cov', absorb(`delta_dist') vce(cluster cbg0 cbg1) resid
predict `x'_resid, resid
}

binscatter delta_share_BEV_resid delta_P_gas_resid, line(lfit) n(`numpoints') ///
xtitle("Gasoline Price Differential (cpg)") ytitle("Electric Vehicle Adoption Differential (EVs / 10k pop)")
graph export "${ResultsOut}/Figures/RF_Dpgas_vs_Dbev.pdf", replace 

binscatter delta_share_BEV_resid delta_p_e_active_resid, line(lfit) n(`numpoints') ///
xtitle("Electricity Price Differential (cents/kwh)") ytitle("Electric Vehicle Adoption Differential (EVs / 10k pop)")
graph export "${ResultsOut}/Figures/RF_Dpe_vs_Dbev.pdf", replace 

binscatter delta_share_BEV_resid delta_owP_gas_lt3_resid, line(lfit) n(`numpoints') ///
xtitle("Gasoline Price Differential (cpg)") ytitle("Electric Vehicle Adoption Differential (EVs / 10k pop)")
graph export "${ResultsOut}/Figures/RF_Dpgas_lt3_vs_Dbev.pdf", replace 


binscatter delta_share_BEV_resid delta_P_gas_permile_resid, line(lfit) n(`numpoints') ///
xtitle("Gasoline Price Differential (cents per mile)") ytitle("Electric Vehicle Adoption Differential (EVs / 10k pop)") ///
xscale(range(-4 4)) xlabel(-4 (2) 4) yscale(range(-4 4)) ylabel(-4 (2) 4)

graph export "${ResultsOut}/Figures/RF_Dpgas_vs_Dbev_permile.pdf", replace 

binscatter delta_share_BEV_resid delta_p_e_permile_resid, line(lfit) n(`numpoints') ///
xtitle("Electricity Price Differential (cents per mile)") ytitle("Electric Vehicle Adoption Differential (EVs / 10k pop)") ///
xscale(range(-4 4)) xlabel(-4 (2) 4) yscale(range(-4 4)) ylabel(-4 (2) 4)

graph export "${ResultsOut}/Figures/RF_Dpe_vs_Dbev_permile.pdf", replace 

binscatter delta_share_BEV_resid delta_owP_gas_lt3_pm_resid, line(lfit) n(`numpoints') ///
xtitle("Gasoline Price Differential (cents per mile)") ytitle("Electric Vehicle Adoption Differential (EVs / 10k pop)") ///
xscale(range(-4 4)) xlabel(-4 (2) 4) yscale(range(-4 4)) ylabel(-4 (2) 4)

graph export "${ResultsOut}/Figures/RF_Dpgas_lt3_vs_Dbev_permile.pdf", replace 


